'use strict';
/**
 * Created by FreezeSoul on 2015/9/30.
 */
define([
        'angular',
        'adConfig',
        'app/modules/login/define'
    ],
    function (angular, adConfig) {
        angular.module('ad.login')
            .factory("adLoginService", ['$http', '$q', 'adRequest', function ($http, $q, adRequest) {

                function login(username, password) {
                    var deferred = $q.defer();
                    var url = adConfig.baseServiceUrl + 'user/login';
                    adRequest(url, {
                        username: username, password: password
                    }).success(function (data, status, headers, config) {
                        deferred.resolve(data);
                    }).error(function (data, status, headers, config) {
                        deferred.reject(status);
                    });
                    return deferred.promise;
                }

                return {
                    login: login
                };
            }]);
    });